package com.hiof.moraa.server.controller;

import com.hiof.moraa.server.service.FeedService;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Bergy
 */
@Controller
public class MainPageController {
    @Autowired
    FeedService feedService;

    public void setFeedService(FeedService feedService) {
        this.feedService = feedService;
    }       
    
    @RequestMapping({"/", "/home"})
    public String showHomePage(
            @RequestParam int routeId,
            Map<String, Object> model,
            HttpServletRequest request) {
        model.put("feedList", feedService.getLatestFeedsOfOneRoute(routeId));
        String serverName = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        model.put("serverName", serverName);
        model.put("routeId", routeId);
        return "home";
    }
}
